from django import template
from django.shortcuts import render_to_response
from django.template import resolve_variable

register = template.Library()

def do_hcard(parser, token):
    try:
        tag_name, obj = token.split_contents()
    except ValueError, e:
        raise template.TemplateSyntaxError, "%s requires a single argument" % token.contents.split()[0]

    return HCardRender(obj)

class HCardRender(template.Node):
    obj = None

    def __init__(self, obj):
        self.obj = template.Variable(obj)

    def render(self, context):
        try:
            obj = self.obj.resolve(context)
            return render_to_response('microformats/hcard.html',{'object': obj},)
        except template.VariableDoesNotExist, e:
            return ''

register.tag('hcard', do_hcard)

